package com.heima.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.heima.common.PageResult;
import com.heima.mapper.OrderMapper;
import com.heima.pojo.Order;
import com.heima.pojo.dto.OrderQueryDTO;
import com.heima.pojo.vo.OrderVO;
import com.heima.service.IOderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements IOderService {
    @Override
    public PageResult<OrderVO> search(OrderQueryDTO orderQueryDTO) {
        // 创建分页对象
        Page<OrderVO> page = new Page<>(orderQueryDTO.getPageIndex(), orderQueryDTO.getPageSize());

        // 调用 mapper 的分页查询方法
        IPage<OrderVO> result = baseMapper.pageOrder(page, orderQueryDTO);

        // 返回分页结果
        return new PageResult<>(
                orderQueryDTO.getPageIndex(),
                orderQueryDTO.getPageSize(),
                (int) result.getPages(),
                result.getTotal(),
                result.getRecords()
        );
    }
}
